﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Ryder_US_Website.BUS;

namespace Ryder_US_Website.Presentation.Admin
{
    public partial class ServiceDetail_Insert : System.Web.UI.Page
    {
        protected void DropdownlistLoad()
        {
            List<RUS_Service> list = ServiceBUS.GetAll();
            DropDownListTenDichVu.DataSource = list;
            DropDownListTenDichVu.DataTextField = "Service_name";
            DropDownListTenDichVu.DataValueField = "Service_ID";
            DropDownListTenDichVu.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["RUS_User"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            //if(!IsPostBack)
            //{
                DropdownlistLoad();
            //}

        }
        
        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("ServiceDetail_List.aspx");
        }

        protected void DropDownListTenDichVu_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        protected void btnThem_Click(object sender, EventArgs e)
        {
            RUS_ServiceDetail sd=new RUS_ServiceDetail();
            sd.ServiceDetail_ServiceID = Int16.Parse(DropDownListTenDichVu.SelectedItem.Value);
            sd.ServiceDetail_name = txtTenChiTietDV.Text;
            sd.ServiceDetail_description = txtMoTa.Text;
            sd.ServiceDetail_price = Decimal.Parse(txtDonGia.Text);
            sd.ServiceDetail_unit = txtDonViTinh.Text;
            sd.ServiceDetail_unitMin = Int16.Parse(txtTrongLuongMin.Text);
            sd.ServiceDetail_unitMax = Int16.Parse(txtTrongLuongMax.Text);
            try
            {
                sd = ServiceDetailBUS.Insert(sd.ServiceDetail_ServiceID, sd.ServiceDetail_name, sd.ServiceDetail_unit,
                                             sd.ServiceDetail_unitMin,
                                             sd.ServiceDetail_unitMax, sd.ServiceDetail_price,
                                             sd.ServiceDetail_description);
            }
            catch(Exception ex)
            {
                Response.Write(Utils.UtilHelpers.ShowMessage(ex.Message));
            }
            if(txtTenChiTietDV.Text!="")
            {
                Response.Write(Utils.UtilHelpers.ShowMessage("Thêm chi tiết dịch vụ thành công"));
                Response.Redirect("ServiceDetail_List.aspx");
            }
            else
            {
                Response.Write(Utils.UtilHelpers.ShowMessage("Thêm chi tiết dịch vụ thất bại"));
            }
        }
    }
}
